package com.feihong.yw189.activity.shouye;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.feihong.yw189.R;
import com.feihong.yw189.activity.base.BaseActivity;
import com.feihong.yw189.bluetooth.activity.SearchBlueActivity;
import com.feihong.yw189.bluetooth.dialog.MyUsualyDialog;
import com.feihong.yw189.message.LoginMessage;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 补卡页面   主页
 */

public class KeHuYanZhengActivity extends BaseActivity {


    @BindView(R.id.rl_goback)
    RelativeLayout ivBack;
    @BindView(R.id.iv_lin)
    ImageView ivLin;
    @BindView(R.id.txt_pagetitle)
    TextView txtPagetitle;
    @BindView(R.id.rl_saomiao)
    RelativeLayout rlSaoMiao;
    /*--------------*/
    @BindView(R.id.tv_xmtext)
    TextView tvXMtext;
    @BindView(R.id.tv_username)
    TextView mIDCardName;
    @BindView(R.id.txt_idcardnumber)
    TextView tvIdcardNumber;
    @BindView(R.id.txt_idnumber)
    TextView mIDCardNum;
    @BindView(R.id.iv_headPhote)
    ImageView mIDCardImg;
    @BindView(R.id.rl_idcardinfo)
    RelativeLayout  rlIDcardInfo;


    @BindView(R.id.real_name_auth_title_tv)
    TextView mSubTitle;

    Intent mInetent;
    private String bukaNumber;
    private String yanzheng;
    public static final int YanZhengIdcard = 1580;
    private TextView[] tvPhoneNum = new TextView[5];
    private RelativeLayout[] rlPhoneNum = new RelativeLayout[5];
    /**
     * 套餐组id  套餐id 号码id  ICCID id 证件号码 证件名称  联系方式
     */
    private String mPackageGroupID = null, mPhoneNumID = null,
            mPackageID = null, mICCID_ID = null, mIDCard_Num = null,
            mIDCard_Name = null, mContactPhone = null;
    private MyUsualyDialog dialog;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_kehuyanzheng);
        ButterKnife.bind(this);

        initView();
        initData();
    }

    @Override
    public void setTheme() {

    }

    @Override
    public void onUserLogin(LoginMessage loginMessage) {

    }

    private void initView() {
        mSubTitle.setTextSize(14);
        tvPhoneNum[0] = (TextView) findViewById(R.id.tvphoneNum);
        tvPhoneNum[1] = (TextView) findViewById(R.id.tvphoneNum1);
        tvPhoneNum[2] = (TextView) findViewById(R.id.tvphoneNum2);
        tvPhoneNum[3] = (TextView) findViewById(R.id.tvphoneNum3);
        tvPhoneNum[4] = (TextView) findViewById(R.id.tvphoneNum4);

        rlPhoneNum[0] = (RelativeLayout) findViewById(R.id.rl_one);
        rlPhoneNum[1] = (RelativeLayout) findViewById(R.id.rl_two);
        rlPhoneNum[2] = (RelativeLayout) findViewById(R.id.rl_three);
        rlPhoneNum[3] = (RelativeLayout) findViewById(R.id.rl_four);
        rlPhoneNum[4] = (RelativeLayout) findViewById(R.id.rl_five);


        txtPagetitle.setText("客户验证");
        ivLin.setVisibility(View.GONE);
        rlIDcardInfo.setVisibility(View.VISIBLE);



    }

    private void initData() {
        dialog = new MyUsualyDialog(KeHuYanZhengActivity.this, R.layout.wait_item);
        dialog.setCanceledOnTouchOutside(false);
        dialog.setCancelable(false);
    }

    @OnClick({R.id.rl_goback, R.id.rl_saomiao
    })
    public void onViewClicked(View v) {
        switch (v.getId()) {
            case R.id.rl_goback:
                finish();//返回
                break;
            case R.id.rl_saomiao:

                mInetent = new Intent(this, SearchBlueActivity.class);
                mInetent.putExtra("isUpData", true);
                mInetent.putExtra("isRead", true);
                mInetent.putExtra("isTest", "1");
                startActivityForResult(mInetent, YanZhengIdcard);
                break;
                default:break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (data != null) {
            switch (requestCode) {
                case YanZhengIdcard:

                    //身份证照片上传  //扫身份证  结果
                    Bundle bundle = data.getExtras();
                    if (bundle != null) {
                        mIDCard_Num = bundle.getString("id_num");
                        mIDCard_Name = bundle.getString("name");
                        byte[] photo = bundle.getByteArray("photo");
                        String filePhoto = bundle.getString("filePhoto");
                        Bitmap bitmap = BitmapFactory.decodeByteArray(photo, 0, photo.length);
                        String photoHeard = bundle.getString("photoHeard");
                        tvXMtext.setVisibility(View.VISIBLE);
                        mIDCardName.setText(mIDCard_Name);
                        tvIdcardNumber.setVisibility(View.VISIBLE);
                        mIDCardNum.setText(mIDCard_Num);
                        mIDCardImg.setImageBitmap(bitmap);

                        int  count = bundle.getInt("count");
                        ArrayList<String> object = bundle.getStringArrayList("phoneList");
                        if(object.size() > 0){
                            for (int i = 0; i < rlPhoneNum.length; i++) {
                                rlPhoneNum[i].setVisibility(View.GONE);
                            }
                            if(count >= 0){
                                for (int i = 0; i < count; i++) {
                                    rlPhoneNum[i].setVisibility(View.VISIBLE);
                                    tvPhoneNum[i].setText(object.get(i));
                                }
                            }
                        }
                    }
                    break;
                    default:break;
            }
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (dialog != null) {
            dialog.dismiss();
        }
    }
}
